const path = require("path");
const glob = require("glob");
const vuePlugin = require("vue-loader/lib/plugin")

// 自动加载所有组件
const makeList = function(dir) {
    // 匹配所有文件
    const files = glob.sync(`${dir}/**/index.js`);
    let result = {};
    for (let file of files) {
        const name = file.split("/")[2];
        result[name] = path.join(__dirname,file);
    }
    return result;
}

const list = makeList("components/lib");

module.exports = {
    entry: list,
    output: {
        filename: '[name].umd.js',
        path: path.join(__dirname,"/dist"),
        // 暴露的全局变量
        library: 'lin-ui',
        libraryTarget: 'umd'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.(jpg|png)$/,
                loader: 'url-loader',
                options: {
                    limit: 102400,
                    publicPath: './images/'
                }
            }
        ]
    },
    plugins: [
        new vuePlugin()
    ],
    mode: 'development'
}